package com.glsc.ngateway.opmanage.service.report.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.glsc.ngateway.common.base.domain.mysql.opmanage.report.FileUploadLog;
import com.glsc.ngateway.common.base.domain.mysql.opmanage.report.excel.*;
import com.glsc.ngateway.common.base.domain.mysql.opmanage.report.excel.hyproject.*;
import com.glsc.ngateway.common.base.domain.mysql.opmanage.report.fileupload.*;
import com.glsc.ngateway.common.base.domain.mysql.opmanage.report.regulatory.*;
import com.glsc.ngateway.common.base.dto.opmanage.report.ExcelUploadDto;
import com.glsc.ngateway.common.base.dto.opmanage.report.ImportFileDto;
import com.glsc.ngateway.common.base.repo.mysql.opmanage.report.FileUploadLogRepository;
import com.glsc.ngateway.common.base.repo.mysql.opmanage.report.excel.*;
import com.glsc.ngateway.common.base.repo.mysql.opmanage.report.fileupload.*;
import com.glsc.ngateway.common.base.repo.mysql.opmanage.report.hyproject.*;
import com.glsc.ngateway.common.base.repo.mysql.opmanage.report.regulatory.*;
import com.glsc.ngateway.opmanage.aspect.JwtHelper;
import com.glsc.ngateway.opmanage.service.UserService;
import com.glsc.ngateway.opmanage.service.report.excel.listener.*;
import com.glsc.ngateway.opmanage.service.report.excel.listener.hyproject.*;
import com.glsc.ngateway.opmanage.service.report.excel.listener.regulatory.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.CallableStatementCallback;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.math.BigInteger;
import java.sql.CallableStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Service
@Transactional(transactionManager = "transactionManagerMysql")
public class ExcelUploadService {

    private static final Logger logger = LoggerFactory.getLogger(ExcelUploadService.class);
    @Autowired
    NamedParameterJdbcTemplate namedParameterJdbcTemplateMysql;

    @Qualifier("mysqlglscdataJdbcTemplate")
    @Autowired
    private JdbcTemplate jdbcTemplateMysql;

    @Autowired
    private FileUploadLogRepository fileUploadLogRepository;

    @Autowired
    private TImportConfigRepo tImportConfigRepo;

    @Autowired
    private FileUploadRelateImportRepo fileUploadRelateImportRepo;

    @Autowired
    private TImportStatusRepo tImportStatusRepo;

    @Autowired
    private UserService userService;

    @Autowired
    private TImportLogRepo tImportLogRepo;

    @Autowired
    private NAVPerShsRepo navPerShsRepo;

    @Autowired
    private PnLTrdLvRepository pnLTrdLvRepo;

    @Autowired
    private RiskDailyStockRepoAmRepo riskDailyStockRepoAmRepo;

    @Autowired
    private RiskDailyStockRepoPropRepo riskDailyStockRepoPropRepo;

    @Autowired
    private RiskDailyStockRepoExecRepo riskDailyStockRepoExecRepo;

    @Autowired
    private RiskdailyStockRepoSzPropRepo riskdailyStockRepoSzPropRepo;

    @Autowired
    private RiskdailyStockRepoSzAmRepo riskdailyStockRepoSzAmRepo;

    @Autowired
    private PnLInstrLvRepo pnLInstrLvRepo;

    @Autowired
    private PnLTrdLvRepoRepo pnLTrdLvRepoRepo;

    @Autowired
    private CashPosRepo cashPosRepo;

    @Autowired
    private ECMRepo ecmRepo;

    @Autowired
    private ECMIFARepo ecmifaRepo;

    @Autowired
    private DCMNowRepo dcmNowRepo;

    @Autowired
    private DCMFutureRepo dcmFutureRepo;

    @Autowired
    private DCMFinshedRepo dcmFinshedRepo;

    @Autowired
    private TRSRepo trsRepo;

    @Autowired
    private GltbFundListRepo gltbFundListRepo;

    @Autowired
    private GltbSubFundListRepo gltbSubFundListRepo;

    @Autowired
    private GltbFundPositionRepo gltbFundPositionRepo;

    @Autowired
    private GltbFundStatusRepo gltbFundStatusRepo;

    @Autowired
    private DurationBondRepo durationBondRepo;

    @Autowired
    private DurationListedCompanyRepo durationListedCompanyRepo;

    @Autowired
    private DurationNewThirdRepo durationNewThirdRepo;

    @Autowired
    private DurationStockRepo durationStockRepo;

    @Autowired
    private EstablishmentRepo establishmentRepo;

    @Autowired
    private EstablishmentNewThirdRepo establishmentNewThirdRepo;

    @Autowired
    private PreEstablishmentRepo preEstablishmentRepo;

    @Autowired
    private HyProjectMatchRepo hyProjectMatchRepo;

    @Autowired
    private HyKernelProjectRepo hyKernelProjectRepo;

    @Autowired
    private RegRptDefineRepo regRptDefineRepo;
    @Autowired
    private RegRptMainRepo regRptMainRepo;
    @Autowired
    private RegRptInterOtcA1Repo regRptInterOtcA1Repo;
    @Autowired
    private RegRptInterOtcA2Repo regRptInterOtcA2Repo;
    @Autowired
    private RegRptInterOtcA3Repo regRptInterOtcA3Repo;
    @Autowired
    private RegRptInterOtcA4Repo regRptInterOtcA4Repo;
    @Autowired
    private RegRptInterOtcA9Repo regRptInterOtcA9Repo;
    @Autowired
    private RegRptInterOtcA11Repo regRptInterOtcA11Repo;
    @Autowired
    private RegRptInterOtcA12Repo regRptInterOtcA12Repo;
    @Autowired
    private RegRptInterOtcA13Repo regRptInterOtcA13Repo;
    @Autowired
    private RegRptNAFMIIOtherRepo tnafmiiOtherRepo;
    @Autowired
    private RegRptNAFMIIScaleRepo tnafmiiScaleRepo;
    @Autowired
    private RegRptNAFMIIProtocolRepo tnafmiiProtocolRepo;
    @Autowired
    private RegRptNAFMIIIRSRepo tnafmiiirsRepo;
    @Autowired
    private RegRptSelfMarketMakingRepo tSelfMarketMakingRepo;
    @Autowired
    private ImportTemplateRulesDefineRepo importTemplateRulesDefineRepo;
    @Autowired
    private RegRptSAJSIMSRepo regRptSAJSIMSRepo;
    @Autowired
    private RegRptBondMngRepo regRptBondMngRepo;

    @Transactional
    public FileUploadRelateImport saveRelateImport(FileUploadRelateImport fileUploadRelateImport) {
        fileUploadRelateImportRepo.save(fileUploadRelateImport);
        return fileUploadRelateImport;
    }

    @Transactional
    public Long relateImportMaxId() {

        return fileUploadRelateImportRepo.queryMaxId();
    }

    @Transactional
    public Long findByFileId(String fileId) {
        return fileUploadRelateImportRepo.findByFileId(fileId).getId();
    }

    @Transactional
    public int deleteRelateImport(Long id) {
        return fileUploadRelateImportRepo.deleteById(id);
    }
    
    @Transactional
    public int deleteRelateImport(List<Long> idList) {
        return fileUploadRelateImportRepo.deleteByIdList(idList);
    }

    public List<ImportFileDto> importFileList(String catid, String bizdate, String dimension1) {
        return fileUploadRelateImportRepo.queryImportFile(catid, bizdate, dimension1);
    }

    public List<JSONObject> listStatus(String catid, String bizdate, String dimension1) {
        return tImportStatusRepo.queryImportStatus(catid, bizdate, dimension1);
    }

    public List<String> queryBizdateByCatid(String catid) {
        return fileUploadRelateImportRepo.queryBizdateByCatId(catid);
    }

    public List<List> doRecovery(ExcelUploadDto dto) throws Exception {
        List<List> ret = new ArrayList<>();
        try {
            String catid = dto.getCatid();
            String bizdate = dto.getBizdate();
            String dimension1 = dto.getDimension1();
            JSONArray jsonArray = dto.getData();

            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                List param2Value = (List) jdbcTemplateMysql.execute(
                        con -> {
                            String storedProc = "{CALL glsc_data.p_import_undo" + "(?,?,?,?,?,?)}";// 调用的sql
                            CallableStatement cs = con.prepareCall(storedProc);
                            cs.setString(1, bizdate); //设置输入参数
                            cs.setString(2, catid); //设置输入参数
                            cs.setLong(3, jsonObject.getLong("importid"));
                            cs.setString(4, dimension1);
                            cs.registerOutParameter(5, 4);//设置输出参数 —— 必须在执行存储过程之前进行注册
                            cs.registerOutParameter(6, 12);
                            return cs;
                        }, new CallableStatementCallback() {
                            @Override
                            public Object doInCallableStatement(CallableStatement cs) throws SQLException,
                                    DataAccessException {
                                List<String> res = new ArrayList<>();
                                cs.execute();
                                Integer a = cs.getInt(5);
                                String s = String.valueOf(a);
                                res.add(s);
                                String ss = cs.getString(6);
                                res.add(ss);
                                return res;
                            }
                        });
                ret.add(param2Value);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return ret;
    }

    public HashMap<String, String> doImport(ExcelUploadDto dto, HttpServletRequest request) {
        String catid = dto.getCatid();
        String bizdate = dto.getBizdate();
        String dimension1 = dto.getDimension1();
        JSONArray jsonArray = dto.getData();
        HashMap<String, String> ret = new HashMap<>();

        try {
            doRecovery(dto);
        } catch (Exception e) {
            logger.error(e.getMessage());
            ret.put("decovery", e.getMessage());
            return ret;
        }

        try {
            List<Long> importIds = new ArrayList<>();
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                importIds.add(jsonObject.getLong("importid"));
            }

            List<TImportConfig> config = tImportConfigRepo.findByIdIn(importIds);

            List<ImportFileDto> files = fileUploadRelateImportRepo.queryImportFile(catid, bizdate, dimension1);
            List<String> fileids = new ArrayList<>();
            for (ImportFileDto importFileDto : files) {
                fileids.add(importFileDto.getFileId());
            }
            List<FileUploadLog> logs = fileUploadLogRepository.getByIdIn(fileids);

            String username = "";
            String token = request.getHeader("token");
            if (userService.isInvokeGatewaySSO(token, "token")) {
                username = userService.getIdFromToken(token);
            } else {
                username = JwtHelper.parseToken(token).trim();
            }

            for (TImportConfig tImportConfig : config) {
                ret.put(tImportConfig.getCaption(), handleImport(logs, catid, bizdate, tImportConfig, dimension1, username).toString());
            }
            return ret;
        } catch (Exception e) {
            ret.put("doimport", e.getMessage());
            logger.error(e.getMessage());
            return ret;
        }
    }

    private HashMap<String, String> handleImport(List<FileUploadLog> logs, String catid, String bizdate,
                                                 TImportConfig tImportConfig, String dimension1, String username) {
        HashMap<String, String> ret = new HashMap<>();
        if (CollectionUtils.isEmpty(logs)) {
            return ret;
        }
        Long importId = tImportConfig.getId();
        BigInteger iImportId = BigInteger.valueOf(importId);
        String pattern = tImportConfig.getName();
        TImportStatus tImportStatus = new TImportStatus();
        tImportStatus.setCatId(catid);
        tImportStatus.setBizdate(bizdate);
        tImportStatus.setImportId(importId);
        tImportStatus.setDimension1(dimension1);
        tImportStatus.setStatus(2);
        tImportStatus.setBeginTime(LocalDateTime.now());
        tImportStatus.setModifier(username);

        String sheet = "";
        boolean success = true;
        if (catid.equals("A01")) {
            if (importId == 1) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();
                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                            Date date = simpleDateFormat.parse(bizdate);
                            sheet = "PnLTrdLv";
                            EasyExcel.read(path, PnLTrdLv.class, new PnLTrdLvListener(pnLTrdLvRepo, fileUploadLog.getFileName().split("_")[1], date)).sheet("PnLTrdLv").headRowNumber(1).doRead();
                            sheet = "NAVPerShs";
                            EasyExcel.read(path, NAVPerShs.class, new NAVPerShsListener(navPerShsRepo, fileUploadLog.getFileName().split("_")[1], date)).sheet("NAVPerShs").headRowNumber(2).doRead();
                            sheet = "PnLInstrLv";
                            EasyExcel.read(path, PnLInstrLv.class, new PnLInstrLvListener(pnLInstrLvRepo, fileUploadLog.getFileName().split("_")[1], date)).sheet("PnLInstrLv").headRowNumber(1).doRead();
                            sheet = "PnLTrdLvRepo";
                            EasyExcel.read(path, PnLTrdLvRepo.class, new PnLTrdLvRepoListener(pnLTrdLvRepoRepo, fileUploadLog.getFileName().split("_")[1], date)).sheet("PnLTrdLvRepo").headRowNumber(1).doRead();
                            sheet = "CashPos";
                            EasyExcel.read(path, CashPos.class, new CashPosListener(cashPosRepo, date)).sheet("CashPos").headRowNumber(1).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 2) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();
                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                            Date date = simpleDateFormat.parse(bizdate);
                            sheet = "PnLSumm";
                            EasyExcel.read(path, NAVPerShs.class, new NAVPerShsListener(navPerShsRepo, "Guolian Securities (H.K.) Co., Limited", date)).sheet("PnLSumm").headRowNumber(2).doRead();
                            sheet = "PnLTrdLv";
                            EasyExcel.read(path, PnLTrdLv.class, new PnLTrdLvListener(pnLTrdLvRepo, "Guolian Securities (H.K.) Co., Limited", date)).sheet("PnLTrdLv").headRowNumber(1).doRead();
                            sheet = "PnLInstrLv";
                            EasyExcel.read(path, PnLInstrLv.class, new PnLInstrLvListener(pnLInstrLvRepo, "Guolian Securities (H.K.) Co., Limited", date)).sheet("PnLInstrLv").headRowNumber(1).doRead();
                            sheet = "RepoTrdLv";
                            EasyExcel.read(path, PnLTrdLvRepo.class, new PnLTrdLvRepoListener(pnLTrdLvRepoRepo, "Guolian Securities (H.K.) Co., Limited", date)).sheet("RepoTrdLv").headRowNumber(1).doRead();
                            sheet = "CashPos";
                            EasyExcel.read(path, CashPos.class, new CashPosListener(cashPosRepo, date)).sheet("CashPos").headRowNumber(1).doRead();
                            sheet = "TRS";
                            EasyExcel.read(path, TRS.class, new TRSListener(trsRepo, date)).sheet("TRS").headRowNumber(1).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 3) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();
                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                            Date date = simpleDateFormat.parse(bizdate);
                            sheet = "Now";
                            EasyExcel.read(path, DCMNow.class, new DCMNowListener(dcmNowRepo, date)).sheet("Now").headRowNumber(1).doRead();
                            sheet = "Finished";
                            EasyExcel.read(path, DCMFinished.class, new DCMFinishedListener(dcmFinshedRepo, date)).sheet("Finished").headRowNumber(1).doRead();
                            sheet = "Future";
                            EasyExcel.read(path, DCMFuture.class, new DCMFutureListener(dcmFutureRepo, date)).sheet("Future").headRowNumber(1).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 4) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();
                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                            Date date = simpleDateFormat.parse(bizdate);
                            sheet = "ECM";
                            EasyExcel.read(path, ECM.class, new ECMListener(ecmRepo, date)).sheet("ECM").headRowNumber(1).doRead();
                            sheet = "IFA";
                            EasyExcel.read(path, ECMIFA.class, new ECMIFAListener(ecmifaRepo, date)).sheet("IFA").headRowNumber(1).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
        }
        if (catid.equals("B01")) {
            if (importId == 5) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();
                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                            Date date = simpleDateFormat.parse(bizdate);
                            sheet = "基金列表";
                            EasyExcel.read(path, GltbFundList.class, new GltbFundListListener(gltbFundListRepo, date)).sheet("基金列表").headRowNumber(1).doRead();
                            sheet = "子基金列表";
                            EasyExcel.read(path, GltbSubFundList.class, new GltbSubFundListListener(gltbSubFundListRepo, date)).sheet("子基金列表").headRowNumber(1).doRead();
                            sheet = "基金持仓明细";
                            EasyExcel.read(path, GltbFundPosition.class, new GltbFundPositionListener(gltbFundPositionRepo)).sheet("基金持仓明细").headRowNumber(1).doRead();
                            sheet = "基金财务情况";
                            EasyExcel.read(path, GltbFundStatus.class, new GltbFundStatusListener(gltbFundStatusRepo)).sheet("基金财务情况").headRowNumber(1).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
        }
        if (catid.equals("C01")) {
            if (importId == 6) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();

                            File file = new File(path);
                            ExcelReaderBuilder excelReaderBuilder = EasyExcel.read(file);
                            ExcelReader excelReader = excelReaderBuilder.build();
                            List<ReadSheet> sheets = excelReader.excelExecutor().sheetList();

                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                            Date date = simpleDateFormat.parse(bizdate);

                            for (ReadSheet readSheet : sheets) {
                                sheet = readSheet.getSheetName();
                                if (sheet.equals("1预立项-股票（辅导）保荐承销") || sheet.equals("2预立项-上市公司并购重组") || sheet.equals("3预立项-新三板") || sheet.equals("4预立项-其他财务顾问") || sheet.equals("5预立项-债券类项目")) {
                                    EasyExcel.read(path, PreEstablishment.class, new PreEstablishmentListener(preEstablishmentRepo, date, sheet)).sheet(sheet).headRowNumber(3).doRead();
                                }
                                if (sheet.equals("6立项-股票（辅导）保荐承销") || sheet.equals("7立项-上市公司并购重组") || sheet.equals("9立项-其他财务顾问") || sheet.equals("10立项-债券承销")) {
                                    EasyExcel.read(path, Establishment.class, new EstablishmentListener(establishmentRepo, date, sheet)).sheet(sheet).headRowNumber(3).doRead();
                                }
                                if (sheet.equals("8立项-新三板")) {
                                    EasyExcel.read(path, EstablishmentNewThird.class, new EstablishmentNewThirdListener(establishmentNewThirdRepo, date, sheet)).sheet(sheet).headRowNumber(3).doRead();
                                }
                                if (sheet.equals("11持续督导期-股票（辅导保荐承销）")) {
                                    EasyExcel.read(path, DurationStock.class, new DurationStockListener(durationStockRepo, date, sheet)).sheet(sheet).headRowNumber(3).doRead();
                                }
                                if (sheet.equals("12持续督导期-上市公司并购重组")) {
                                    EasyExcel.read(path, DurationListedCompany.class, new DurationListedCompanyListener(durationListedCompanyRepo, date, sheet)).sheet(sheet).headRowNumber(3).doRead();
                                }
                                if (sheet.equals("13持续督导期-新三板")) {
                                    EasyExcel.read(path, DurationNewThird.class, new DurationNewThirdListener(durationNewThirdRepo, date, sheet)).sheet(sheet).headRowNumber(3).doRead();
                                }
                                if (sheet.equals("14存续期-债券承销")) {
                                    EasyExcel.read(path, DurationBond.class, new DurationBondListener(durationBondRepo, date, sheet)).sheet(sheet).headRowNumber(3).doRead();
                                }
                            }
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 7) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();

                            EasyExcel.read(path, HyKernelProject.class, new HyKernelProjectListener(hyKernelProjectRepo)).sheet(0).headRowNumber(1).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 8) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();

                            EasyExcel.read(path, HyProjectMatch.class, new HyProjectMatchListener(hyProjectMatchRepo)).sheet(0).headRowNumber(1).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
        }
        if ("D01".equals(catid)) {
            if (importId == 9) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();
                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                            Date date = simpleDateFormat.parse(bizdate);
                            sheet = "基础数据表";
                            EasyExcel.read(path, RiskDailyStockRepoAm.class, new RiskDailyStockRepoAmListener(riskDailyStockRepoAmRepo, sheet, date)).sheet(sheet).headRowNumber(1).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 19) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();
                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                            Date date = simpleDateFormat.parse(bizdate);
                            sheet = "融资规模";
                            EasyExcel.read(path, RiskdailyStockRepoSzAm.class, new RiskdailyStockRepoSzAmListener(riskdailyStockRepoSzAmRepo, date)).sheet(sheet).headRowNumber(12).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
        }
        if ("D02".equals(catid)) {
            if (importId == 10) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();
                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                            Date date = simpleDateFormat.parse(bizdate);
                            sheet = "基础数据表";
                            EasyExcel.read(path, RiskDailyStockRepoProp.class, new RiskDailyStockRepoPropListener(
                                    riskDailyStockRepoPropRepo, sheet, date)).sheet(sheet).headRowNumber(1).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);

                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 18) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();
                            sheet = "融资规模";
                            int headRow=0;

                            File file=new File(path);
                            String fileType = path.substring(path.lastIndexOf(".")+1);
                            InputStream inputStream = new FileInputStream(file);
                            Workbook workbook;
                            if("xlsx".equals(fileType)){
                                workbook = new XSSFWorkbook(inputStream);
                            }else{
                                workbook = new HSSFWorkbook(inputStream);
                            }
                            Sheet sheet1 = workbook.getSheet(sheet);
                            for(int i=0;i<sheet1.getPhysicalNumberOfRows();i++){
                                if(sheet1.getRow(i).getCell(0).getStringCellValue().equals("深交所自营出资新增初始交易规模")){
                                    headRow=i;
                                    break;
                                }
                            }

                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                            Date date = simpleDateFormat.parse(bizdate);

                            EasyExcel.read(path, RiskdailyStockRepoSzProp.class, new RiskdailyStockRepoSzPropListener(
                                    riskdailyStockRepoSzPropRepo, date)).sheet(sheet).headRowNumber(headRow+2).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);

                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
        }
        if ("D03".equals(catid)) {
            if (importId == 11) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);
                        try {
                            String path = fileUploadLog.getPath();
                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                            Date date = simpleDateFormat.parse(bizdate);
                            sheet = "基础数据表";
                            EasyExcel.read(path, RiskDailyStockRepoExec.class, new RiskDailyStockRepoExecListener(
                                    riskDailyStockRepoExecRepo, sheet, date)).sheet(sheet).headRowNumber(1).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);

                                success = false;
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入失败: " + ":" + sheet + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                                success = false;
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
        }
        if ("E01".equals(catid)) {
            Map<BigInteger, BigInteger> idMap = regRptDefineRepo.findByCatId(catid).stream().collect(
                    Collectors.toMap(RegRptDefine::getImportConfigId, RegRptDefine::getId));
            List<ImportTemplateRulesDefine> rulesDefineList = importTemplateRulesDefineRepo.list(iImportId);
            // 新旧模板公用
            if (importId == 12 || importId == 24) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setDimension1(dimension1);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);

                        RegRptMain regRptMain = new RegRptMain();
                        regRptMain.setReportDefineId(idMap.get(iImportId));
                        regRptMain.setBizdate(bizdate);
                        regRptMain.setDimension1(dimension1);
                        regRptMain.setOperator(username);
                        regRptMain.setFileId(fileUploadLog.getId());
                        regRptMain.setStatus(0);
                        try {
                            regRptMainRepo.save(regRptMain);
                            EasyExcel.read(fileUploadLog.getPath(), new RegRptInterOtcA1Listener(regRptInterOtcA1Repo,
                                    regRptMain.getId(), rulesDefineList)).sheet(0).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);
                            success = false;
                            regRptMain.setStatus(1);
                            regRptMainRepo.save(regRptMain);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + " 导入失败: " + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 13) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setDimension1(dimension1);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);

                        RegRptMain regRptMain = new RegRptMain();
                        regRptMain.setReportDefineId(idMap.get(iImportId));
                        regRptMain.setBizdate(bizdate);
                        regRptMain.setDimension1(dimension1);
                        regRptMain.setOperator(username);
                        regRptMain.setFileId(fileUploadLog.getId());
                        regRptMain.setStatus(0);
                        try {
                            regRptMainRepo.save(regRptMain);
                            EasyExcel.read(fileUploadLog.getPath(), new RegRptInterOtcA2Listener(regRptInterOtcA2Repo,
                                    regRptMain.getId(), rulesDefineList)).sheet(0).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);
                            success = false;
                            regRptMain.setStatus(1);
                            regRptMainRepo.save(regRptMain);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + " 导入失败: " + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 14) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setDimension1(dimension1);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);

                        RegRptMain regRptMain = new RegRptMain();
                        regRptMain.setReportDefineId(idMap.get(iImportId));
                        regRptMain.setBizdate(bizdate);
                        regRptMain.setDimension1(dimension1);
                        regRptMain.setOperator(username);
                        regRptMain.setFileId(fileUploadLog.getId());
                        regRptMain.setStatus(0);
                        try {
                            regRptMainRepo.save(regRptMain);
                            EasyExcel.read(fileUploadLog.getPath(), new RegRptInterOtcA3Listener(regRptInterOtcA3Repo,
                                    regRptMain.getId(), rulesDefineList)).sheet(0).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);
                            success = false;
                            regRptMain.setStatus(1);
                            regRptMainRepo.save(regRptMain);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + " 导入失败: " + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 15) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setDimension1(dimension1);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);

                        RegRptMain regRptMain = new RegRptMain();
                        regRptMain.setReportDefineId(idMap.get(iImportId));
                        regRptMain.setBizdate(bizdate);
                        regRptMain.setDimension1(dimension1);
                        regRptMain.setOperator(username);
                        regRptMain.setFileId(fileUploadLog.getId());
                        regRptMain.setStatus(0);
                        try {
                            regRptMainRepo.save(regRptMain);
                            EasyExcel.read(fileUploadLog.getPath(), new RegRptInterOtcA4Listener(regRptInterOtcA4Repo,
                                    regRptMain.getId(), rulesDefineList)).sheet(0).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);
                            success = false;
                            regRptMain.setStatus(1);
                            regRptMainRepo.save(regRptMain);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + " 导入失败: " + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 16 || importId == 25) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setDimension1(dimension1);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);

                        RegRptMain regRptMain = new RegRptMain();
                        regRptMain.setReportDefineId(idMap.get(iImportId));
                        regRptMain.setBizdate(bizdate);
                        regRptMain.setDimension1(dimension1);
                        regRptMain.setOperator(username);
                        regRptMain.setFileId(fileUploadLog.getId());
                        regRptMain.setStatus(0);
                        try {
                            regRptMainRepo.save(regRptMain);
                            EasyExcel.read(fileUploadLog.getPath(), new RegRptInterOtcA9Listener(regRptInterOtcA9Repo,
                                    regRptMain.getId(), rulesDefineList)).sheet(0).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);
                            success = false;
                            regRptMain.setStatus(1);
                            regRptMainRepo.save(regRptMain);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + " 导入失败: " + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 17 || importId == 28) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setDimension1(dimension1);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);

                        RegRptMain regRptMain = new RegRptMain();
                        regRptMain.setReportDefineId(idMap.get(iImportId));
                        regRptMain.setBizdate(bizdate);
                        regRptMain.setDimension1(dimension1);
                        regRptMain.setOperator(username);
                        regRptMain.setFileId(fileUploadLog.getId());
                        regRptMain.setStatus(0);
                        try {
                            regRptMainRepo.save(regRptMain);
                            EasyExcel.read(fileUploadLog.getPath(), new RegRptInterOtcA11Listener(regRptInterOtcA11Repo,
                                    regRptMain.getId(), rulesDefineList)).sheet(0).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);
                            success = false;
                            regRptMain.setStatus(1);
                            regRptMainRepo.save(regRptMain);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + " 导入失败: " + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 26) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setDimension1(dimension1);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);

                        RegRptMain regRptMain = new RegRptMain();
                        regRptMain.setReportDefineId(idMap.get(iImportId));
                        regRptMain.setBizdate(bizdate);
                        regRptMain.setDimension1(dimension1);
                        regRptMain.setOperator(username);
                        regRptMain.setFileId(fileUploadLog.getId());
                        regRptMain.setStatus(0);
                        try {
                            regRptMainRepo.save(regRptMain);
                            EasyExcel.read(fileUploadLog.getPath(), new RegRptInterOtcA12Listener(regRptInterOtcA12Repo,
                                    regRptMain.getId(), rulesDefineList)).sheet(0).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);
                            success = false;
                            regRptMain.setStatus(1);
                            regRptMainRepo.save(regRptMain);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + " 导入失败: " + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 27) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setDimension1(dimension1);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);

                        RegRptMain regRptMain = new RegRptMain();
                        regRptMain.setReportDefineId(idMap.get(iImportId));
                        regRptMain.setBizdate(bizdate);
                        regRptMain.setDimension1(dimension1);
                        regRptMain.setOperator(username);
                        regRptMain.setFileId(fileUploadLog.getId());
                        regRptMain.setStatus(0);
                        try {
                            regRptMainRepo.save(regRptMain);
                            EasyExcel.read(fileUploadLog.getPath(), new RegRptInterOtcA13Listener(regRptInterOtcA13Repo,
                                    regRptMain.getId(), rulesDefineList)).sheet(0).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);
                            success = false;
                            regRptMain.setStatus(1);
                            regRptMainRepo.save(regRptMain);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + " 导入失败: " + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
        }

        if ("E02".equals(catid)) {
            Map<BigInteger, BigInteger> idMap = regRptDefineRepo.findByCatId(catid).stream().collect(
                    Collectors.toMap(RegRptDefine::getImportConfigId, RegRptDefine::getId));
            List<ImportTemplateRulesDefine> rulesDefineList = importTemplateRulesDefineRepo.list(iImportId);
            if (importId == 20) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setDimension1(dimension1);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);

                        RegRptMain regRptMain = new RegRptMain();
                        regRptMain.setReportDefineId(idMap.get(iImportId));
                        regRptMain.setBizdate(bizdate);
                        regRptMain.setDimension1(dimension1);
                        regRptMain.setOperator(username);
                        regRptMain.setFileId(fileUploadLog.getId());
                        regRptMain.setStatus(0);
                        try {
                            regRptMainRepo.save(regRptMain);
                            EasyExcel.read(fileUploadLog.getPath(), RegRptSelfMarketMaking.class, new RegRptSelfMarketMakingListener(
                                    tSelfMarketMakingRepo, regRptMain.getId(), rulesDefineList)).sheet(0).headRowNumber(2).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);
                            success = false;
                            regRptMain.setStatus(1);
                            regRptMainRepo.save(regRptMain);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + " 导入失败: " + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
            if (importId == 21) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setDimension1(dimension1);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);

                        RegRptMain regRptMain = new RegRptMain();
                        regRptMain.setReportDefineId(idMap.get(iImportId));
                        regRptMain.setBizdate(bizdate);
                        regRptMain.setDimension1(dimension1);
                        regRptMain.setOperator(username);
                        regRptMain.setFileId(fileUploadLog.getId());
                        regRptMain.setStatus(0);
                        try {
                            regRptMainRepo.save(regRptMain);
                            EasyExcel.read(fileUploadLog.getPath(), RegRptNAFMIIScale.class, new RegRptNAFMIIScaleListener(
                                    tnafmiiScaleRepo, regRptMain.getId(), rulesDefineList)).sheet("业务统计").headRowNumber(11).doRead();
                            EasyExcel.read(fileUploadLog.getPath(), new RegRptNAFMIIProtocolListener(tnafmiiProtocolRepo,
                                    regRptMain.getId(), rulesDefineList)).sheet("业务统计").headRowNumber(2).doRead();
                            EasyExcel.read(fileUploadLog.getPath(), RegRptNAFMIIIRS.class, new RegRptNAFMIIIRSListener(
                                    tnafmiiirsRepo, regRptMain.getId(), rulesDefineList)).sheet("利率互换明细").headRowNumber(2).doRead();
                            EasyExcel.read(fileUploadLog.getPath(), RegRptNAFMIIOther.class, new RegRptNAFMIIOtherListener(
                                    tnafmiiOtherRepo, regRptMain.getId(), rulesDefineList)).sheet("其他交易明细").headRowNumber(1).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);
                            success = false;
                            regRptMain.setStatus(1);
                            regRptMainRepo.save(regRptMain);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + " 导入失败: " + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
        }

        if ("E03".equals(catid)) {
            Map<BigInteger, BigInteger> idMap = regRptDefineRepo.findByCatId(catid).stream().collect(
                    Collectors.toMap(RegRptDefine::getImportConfigId, RegRptDefine::getId));
            List<ImportTemplateRulesDefine> rulesDefineList = importTemplateRulesDefineRepo.list(iImportId);
            if (importId == 22) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setDimension1(dimension1);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);

                        RegRptMain regRptMain = new RegRptMain();
                        regRptMain.setReportDefineId(idMap.get(iImportId));
                        regRptMain.setBizdate(bizdate);
                        regRptMain.setDimension1(dimension1);
                        regRptMain.setOperator(username);
                        regRptMain.setFileId(fileUploadLog.getId());
                        regRptMain.setStatus(0);
                        try {
                            regRptMainRepo.save(regRptMain);
                            EasyExcel.read(fileUploadLog.getPath(), RegRptSAJSIMS.class, new RegRptSAJSIMSListener(
                                    regRptSAJSIMSRepo, regRptMain.getId(), rulesDefineList)).sheet(0).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);
                            success = false;
                            regRptMain.setStatus(1);
                            regRptMainRepo.save(regRptMain);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + " 导入失败: " + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
        }

        if ("E04".equals(catid)) {
            Map<BigInteger, BigInteger> idMap = regRptDefineRepo.findByCatId(catid).stream().collect(
                    Collectors.toMap(RegRptDefine::getImportConfigId, RegRptDefine::getId));
            List<ImportTemplateRulesDefine> rulesDefineList = importTemplateRulesDefineRepo.list(iImportId);
            if (importId == 23) {
                for (FileUploadLog fileUploadLog : logs) {
                    if (Pattern.matches(pattern, fileUploadLog.getFileName())) {
                        TImportLog tImportLog = new TImportLog();
                        tImportLog.setCatId(catid);
                        tImportLog.setBizdate(bizdate);
                        tImportLog.setImportId(importId);
                        tImportLog.setDimension1(dimension1);
                        tImportLog.setFileId(fileUploadLog.getId());
                        tImportLog.setBeginTime(LocalDateTime.now());
                        tImportLog.setModifier(username);

                        RegRptMain regRptMain = new RegRptMain();
                        regRptMain.setReportDefineId(idMap.get(iImportId));
                        regRptMain.setBizdate(bizdate);
                        regRptMain.setDimension1(dimension1);
                        regRptMain.setOperator(username);
                        regRptMain.setFileId(fileUploadLog.getId());
                        regRptMain.setStatus(0);
                        try {
                            regRptMainRepo.save(regRptMain);
                            EasyExcel.read(fileUploadLog.getPath(), new RegRptBondMngListener(regRptBondMngRepo,
                                    regRptMain.getId(), rulesDefineList)).sheet(0).doRead();
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(0);
                            tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功");
                            ret.put(fileUploadLog.getFileName(), "导入成功");
                        } catch (Exception e) {
                            logger.error(e.getMessage());
                            tImportLog.setEndTime(LocalDateTime.now());
                            tImportLog.setStatus(1);
                            success = false;
                            regRptMain.setStatus(1);
                            regRptMainRepo.save(regRptMain);

                            e.printStackTrace();
                            if (e.getCause() instanceof ExcelDataConvertException) {
                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) e.getCause();
                                String cellMsg = "";
                                CellData cellData = excelDataConvertException.getCellData();
                                //这里有一个celldatatype的枚举值,用来判断CellData的数据类型
                                CellDataTypeEnum type = cellData.getType();
                                if (type.equals(CellDataTypeEnum.NUMBER)) {
                                    cellMsg = cellData.getNumberValue().toString();
                                } else if (type.equals(CellDataTypeEnum.STRING)) {
                                    cellMsg = cellData.getStringValue();
                                } else if (type.equals(CellDataTypeEnum.BOOLEAN)) {
                                    cellMsg = cellData.getBooleanValue().toString();
                                }
                                String errorMsg = String.format("excel表格:%s第%s行,第%s列,数据值为:%s,该数据值不符合要求,请检验后重新导入!<span style=\"color:red\">请检查其他的记录是否有同类型的错误!</span>", sheet, excelDataConvertException.getRowIndex() + 1, excelDataConvertException.getColumnIndex() + 1, cellMsg);

                                tImportLog.setMsg(fileUploadLog.getFileName() + "导入成功: " + errorMsg);
                                ret.put(fileUploadLog.getFileName(), errorMsg);
                            } else {
                                tImportLog.setMsg(fileUploadLog.getFileName() + " 导入失败: " + e.getMessage());
                                ret.put(fileUploadLog.getFileName(), e.getMessage());
                            }
                        } finally {
                            tImportLogRepo.save(tImportLog);
                            tImportStatus.setMsg(ret.toString());
                            tImportStatusRepo.save(tImportStatus);
                        }
                    }
                }
            }
        }

        // 根据是否有id，判断文件匹配
        Long id = tImportStatus.getId();
        if (id != null) {
            if (success) {
                tImportStatusRepo.updateStatus(0, id);
            } else {
                tImportStatusRepo.updateStatus(1, id);
            }
            tImportStatusRepo.updateEndtime(LocalDateTime.now(), id);
        } else {
            ret.put(tImportConfig.getId().toString(), "接口未匹配到文件，已跳过导入");
        }

        return ret;
    }

}
